//
// Created by 12967 on 2022/1/20.
//
#include "AVLtree.h"
int height(treeNode* t){

    if(t!=NULL){
        if(t->height!=0)
            return t->height;
        else{
            int le= height(t->left);
            int ri= height(t->right);
            if(le<=ri){
                t->height=ri+1;
                return (ri+1);
            }
            else{
                t->height=ri+1;
                return (le+1);
            }
        }

    }
    else{
        return 0;
    }
}

int factor(treeNode* t){
    return height(t->left)- height(t->right);
}

void clear(treeNode* t){
    t->height=0;
    if(t->left!=NULL)
        clear(t->left);
    if(t->right!=NULL)
        clear(t->right);
}


long scan(treeNode* t){
    long leftc=0;
    long rightc=0;
    if(t->left!=NULL)
        leftc=scan(t->left);
    if(t->right!=NULL)
        rightc=scan(t->right);
    return (leftc+rightc+1);

}

